package com.exsun.gateway.jt809.codec.protocol;

import exsun.jt808.data.jt809_data.BasicVehicleInfo;
import exsun.jt808.data.jt809_data.ReceiveEntityBase;
import exsun.jt808.data.jt809_data.alarm.slave.DownWarnMsgExgInform;
import exsun.jt808.data.jt809_data.alarm.slave.DownWarnMsgFileListReq;
import exsun.jt808.data.jt809_data.alarm.slave.DownWarnMsgInformTips;
import exsun.jt808.data.jt809_data.alarm.slave.DownWarnMsgUrgeTodoReq;
import exsun.jt808.data.jt809_data.linkmanage.UpConnectRsp;
import exsun.jt808.data.jt809_data.monitor.slave.*;
import exsun.jt808.data.jt809_data.platform.slave.DownPlatformMsgInfoReq;
import exsun.jt808.data.jt809_data.platform.slave.DownPlatformMsgPostQueryReq;
import exsun.jt808.data.jt809_data.statistics.DownTotalRecvBackMsg;
import exsun.jt808.data.jt809_data.vehicledynamic.GnssData;
import exsun.jt808.data.jt809_data.vehicledynamic.slave.*;
import exsun.jt808.data.jt809_data.video.slave.*;
import exsun.jt808.data.util.parse.BitOperator;
import exsun.jt808.data.util.parse.DecoderUtils;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 数据解析
 */
@Service
public class Jt809Decode {
    /**
     * 校验码
     */
    public static int verifyCode;
    /**
     *后续数据长度索引
     */
    private int lenIndex = 24;
    /**
     * 子业务数据部分
     */
    public int dataIndex = 28;

    public int dataIndex2 = 6;


    //================until=============
    public BasicVehicleInfo GetBasicVehicleInfo(byte[] data, int index)
    {
        BasicVehicleInfo obj = new BasicVehicleInfo();
        obj.setVehicleNo(DecoderUtils.parseStringFromBytes(data, index, 21));
        obj.setVehicleColor(DecoderUtils.parseIntFromBytes(data, 21, 1));
        return obj;
    }

    //7字节时间，格式dmyyhMs
    public Date GetDate(byte[] data, int index)
    {
        try {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String str =DecoderUtils.parseIntFromBytes(data, index+2, 2)+"-"+
                    DecoderUtils.parseIntFromBytes(data, index+1, 1)+"-"+
                    DecoderUtils.parseIntFromBytes(data, index, 1)+" "+
                    DecoderUtils.parseIntFromBytes(data, index+4, 1)+":"+
                    DecoderUtils.parseIntFromBytes(data, index+5, 1)+":"+
                    DecoderUtils.parseIntFromBytes(data, index+6, 1);
            return format.parse(str);
        }catch (Exception e) {
            e.printStackTrace();
            return new Date();
        }
    }
    //8字节时间, 此处需要验证是否正确
    public Date GetDateUtc(byte[] data, int index)
    {
        try {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            long time = BitOperator.bytesToLong(data, index, 8);
            return new Date(time*1000);
        }catch (Exception e) {
            e.printStackTrace();
            return new Date();
        }
    }

    public static byte[] utcDateTo8Bytes(Date date){
        return  BitOperator.concatAll(
                BitOperator.integerTo4Bytes(0),
                BitOperator.integerTo4Bytes((int) (date.getTime()/1000L)));
    }

    /**
     * 传入完整消息体，取数据部分内容
     * @param data
     * @return
     */
    public byte[] getDataBody(byte[] data)
    {
        int len = DecoderUtils.parseIntFromBytes(data, lenIndex, 4);
        return DecoderUtils.byteCopy(data, dataIndex, len);
    }



    public GnssData GetGnssData(byte[] data, int index)
    {
        GnssData obj = new GnssData();
        obj.setEncrypt(DecoderUtils.parseIntFromBytes(data, index, 1));
        index +=1;
        obj.setDate(GetDate(data,index));
        index +=7;
        obj.setLon(DecoderUtils.parseIntFromBytes(data, index, 1));
        index +=4;
        obj.setLat(DecoderUtils.parseIntFromBytes(data, index, 4));
        index +=4;
        obj.setVec1(DecoderUtils.parseIntFromBytes(data, index, 4));
        index +=2;
        obj.setVec2(DecoderUtils.parseIntFromBytes(data, index, 2));
        index +=2;
        obj.setMileage(DecoderUtils.parseIntFromBytes(data, index, 2));
        index +=4;
        obj.setDirection(DecoderUtils.parseIntFromBytes(data, index, 2));
        index +=2;
        obj.setAltitude(DecoderUtils.parseIntFromBytes(data, index, 2));
        index +=2;
        obj.setState(DecoderUtils.parseIntFromBytes(data, index, 4));
        index +=4;
        obj.setAlarm(DecoderUtils.parseIntFromBytes(data, index, 4));
        index +=4;
        return obj;
    }


    //=================链路管理业务类 ==============
    /**
     * 主链路登录应答消息
     */
    public UpConnectRsp upConnectRsp(byte[] data)
    {
        UpConnectRsp obj = new UpConnectRsp();
        obj.setResult(DecoderUtils.parseIntFromBytes(data, 0, 1));
        obj.setCheckCode(DecoderUtils.parseIntFromBytes(data, 1, 4));
        return obj;
    }

    /**
     * 主链路注销应答消息
     * @param data
     */
    public void upDisConnectRsp(byte[] data)
    {
        //数据体为空
    }

    /**
     * 主链路连接保持应答消息
     * @param data
     */
    public void upLinkTestRsp(byte[] data)
    {
        //数据体为空
    }

    /**
     * 从链路连接请求消息
     * @param data
     * @return 校验码
     */
    public int downConnectReq(byte[] data)
    {
        return DecoderUtils.parseIntFromBytes(data, 0, 4);
    }

    /**
     * 从链路注销请求消息
     * @param data
     * @return 校验码
     */
    public int downDisConnectReq(byte[] data)
    {
        return DecoderUtils.parseIntFromBytes(data, 0, 4);
    }

    /**
     * 从链路连接保持请求消息
     * @param data
     */
    public void downLinkTestReq(byte[] data)
    {
        //数据体为空
    }

    /**
     * 从链路断开通知消息
     * @param data
     * @return
     * 0：无法连接下级平台指定的服务 IP 与端口；
     * 1：上级平台客户端与下级平台服务端断开；
     * 2：其他原因。
     */
    public int downDisConnectInfo(byte[] data)
    {
        return DecoderUtils.parseIntFromBytes(data, 0, 1);
    }

    /**
     * 上级平台主动关闭链路通知消息
     *
     * @param data
     * @return 上级平台返回的链路关闭原因码
     */
    public int downCloseLinkInfrom(byte[] data) {
        return DecoderUtils.parseIntFromBytes(data, 0, 1);
    }

    //======================信息统计业务类 ==================

    /**
     * 接收车辆定位信息数量通知消息
     * @param data
     */
    public DownTotalRecvBackMsg downTotalRecvBackMsg(byte[] data)
    {
        DownTotalRecvBackMsg obj = new DownTotalRecvBackMsg();
        obj.setDynamicInfoTotal(DecoderUtils.parseIntFromBytes(data, 0, 4));
        obj.setStartTime(GetDateUtc(data, 4));
        obj.setEndTime(GetDateUtc(data, 4+8));
        return obj;
    }

    //=================从链路车辆动态信息交换业务  ==============

    /**
     * 交换车辆定位信息消息
     * @param data
     */
    public DownExgMsgCarLocation downExgMsgCarLocation(byte[] data)
    {
        DownExgMsgCarLocation obj = new DownExgMsgCarLocation();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setGnssData(GetGnssData(data, dataIndex));
        return obj;
    }

    /**
     * 车辆定位信息交换补发消息
     * @param data
     */
    public DownExgMsgHistoryArcossArea downExgMsgHistoryArcossArea(byte[] data)
    {
        DownExgMsgHistoryArcossArea obj = new DownExgMsgHistoryArcossArea();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        int index = dataIndex;
        int count = DecoderUtils.parseIntFromBytes(data, index, 1);
        index+=1;
        List<GnssData> list = new ArrayList<GnssData>();
        for(int n = 0;n<count;n++)
        {
            GnssData item = GetGnssData(data, index);
            index += 36;
            list.add(item);
        }
        obj.setGnssDatas(list);
        return obj;
    }

    /**
     * 交换车辆静态信息消息
     * @param data
     */
    public DownExgMsgCarInfo downExgMsgCarInfo(byte[] data)
    {
        DownExgMsgCarInfo obj = new DownExgMsgCarInfo();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setContent(DecoderUtils.parseStringFromBytes(getDataBody(data)));
        return obj;
    }

    /**
     * 启动车辆定位信息交换请求消息
     * @param data
     */
    public DownExgMsgReturnStartup downExgMsgReturnStartup(byte[] data)
    {
        DownExgMsgReturnStartup obj = new DownExgMsgReturnStartup();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setReasonCode(DecoderUtils.parseIntFromBytes(data, dataIndex, 1));
        return obj;
    }

    /**
     * 结束车辆定位信息交换请求消息
     * @param data
     */
    public DownExgMsgReturnEnd downExgMsgReturnEnd(byte[] data)
    {
        DownExgMsgReturnEnd obj = new DownExgMsgReturnEnd();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setReasonCode(DecoderUtils.parseIntFromBytes(data, dataIndex, 1));
        return obj;
    }

    /**
     * 申请交换指定车辆定位信息应答消息
     * @param data
     */
    public DownExgMsgApplyForMonitorStartupAck downExgMsgApplyForMonitorStartupAck(byte[] data)
    {
        DownExgMsgApplyForMonitorStartupAck obj = new DownExgMsgApplyForMonitorStartupAck();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setResult(DecoderUtils.parseIntFromBytes(data, dataIndex, 1));
        return obj;

    }
    /**
     * 取消申请交换指定车辆定位信息应答消息
     * @param data
     */
    public DownExgMsgApplyForMonitorEndAck downExgMsgApplyForMonitorEndAck(byte[] data)
    {
        DownExgMsgApplyForMonitorEndAck obj = new DownExgMsgApplyForMonitorEndAck();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setResult(DecoderUtils.parseIntFromBytes(data, dataIndex, 1));
        return obj;
    }

    /**
     * 补发车辆定位信息应答消息
     * @param data
     */
    public DownExgMsgApplyHisGnssDataAck downExgMsgApplyHisGnssDataAck(byte[] data)
    {
        DownExgMsgApplyHisGnssDataAck obj = new DownExgMsgApplyHisGnssDataAck();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setResult(DecoderUtils.parseIntFromBytes(data, dataIndex, 1));
        return obj;
    }

    /**
     * 上报驾驶员身份识别信息请求消息
     * @param data
     */
    public DownExgMsgReportDriverInfo downExgMsgReportDriverInfo(byte[] data)
    {
        DownExgMsgReportDriverInfo obj = new DownExgMsgReportDriverInfo();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        return obj;
    }

    /**
     * 上报车辆电子运单请求消息
     * @param data
     */
    public DownExgMsgTakeEwaybillReq downExgMsgTakeEwaybillReq(byte[] data)
    {
        DownExgMsgTakeEwaybillReq obj = new DownExgMsgTakeEwaybillReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        return obj;
    }

    //=======================从链路平台间信息交互业务 =====================

    /**
     * 平台查岗请求消息
     * @param data
     */
    public DownPlatformMsgPostQueryReq downPlatformMsgPostQueryReq(byte[] data)
    {
        DownPlatformMsgPostQueryReq obj = new DownPlatformMsgPostQueryReq();
        obj.setInfoId(DecoderUtils.parseIntFromBytes(data, dataIndex2, 4));
        int len = DecoderUtils.parseIntFromBytes(data, dataIndex2+4, 4);
        obj.setInfoContent(DecoderUtils.parseStringFromBytes(data, dataIndex2+8, len));
        return obj;
    }

    /**
     * 下发平台间报文请求消息
     * @param data
     */
    public DownPlatformMsgInfoReq downPlatformMsgInfoReq(byte[] data)
    {
        DownPlatformMsgInfoReq obj = new DownPlatformMsgInfoReq();
        obj.setInfoId(DecoderUtils.parseIntFromBytes(data, dataIndex2, 4));
        int len = DecoderUtils.parseIntFromBytes(data, dataIndex2+4, 4);
        obj.setInfoContent(DecoderUtils.parseStringFromBytes(data, dataIndex2+8, len));
        return obj;
    }
    //=======================从链路车辆报警信息业务==========================

    /**
     * 报警督办请求消息
     * @param data
     */
    public DownWarnMsgUrgeTodoReq downWarnMsgUrgeTodoReq(byte[] data)
    {
        DownWarnMsgUrgeTodoReq obj = new DownWarnMsgUrgeTodoReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        int index = dataIndex;
        obj.setWarnSrc(DecoderUtils.parseIntFromBytes(data, index, 1));
        index+=1;
        obj.setWarnType(DecoderUtils.parseIntFromBytes(data, index, 2));
        index+=2;
        obj.setWarnTime(GetDateUtc(data, index));
        index+=8;
        obj.setSupervisionId(DecoderUtils.parseIntFromBytes(data, index, 2));
        index+=2;
        obj.setSupervisionEndTime(GetDateUtc(data, index));
        index+=8;
        obj.setSupervisionLevel(DecoderUtils.parseIntFromBytes(data, index, 1));
        index+=1;
        obj.setSupervisor(DecoderUtils.parseStringFromBytes(data, index, 16));
        index+=16;
        obj.setSupervisionTel(DecoderUtils.parseStringFromBytes(data, index, 20));
        index+=20;
        obj.setSupervisionEmal(DecoderUtils.parseStringFromBytes(data, index, 30));
        index+=30;
        return obj;
    }

    /**
     * 报警预警消息
     * @param data
     */
    public DownWarnMsgInformTips downWarnMsgInformTips(byte[] data)
    {
        DownWarnMsgInformTips obj = new DownWarnMsgInformTips();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        int index = dataIndex;
        obj.setWarnSrc(DecoderUtils.parseIntFromBytes(data, index, 1));
        index+=1;
        obj.setWarnType(DecoderUtils.parseIntFromBytes(data, index, 2));
        index+=2;
        obj.setWarnTime(GetDateUtc(data, index));
        index+=8;
        int len = DecoderUtils.parseIntFromBytes(data, index, 4);
        index+=4;
        obj.setWarnContent(DecoderUtils.parseStringFromBytes(data, index, len));
        index+=len;
        return obj;
    }

    /**
     * 实时交换报警信息消息
     * @param data
     */
    public DownWarnMsgExgInform downWarnMsgExgInform(byte[] data)
    {
        DownWarnMsgExgInform obj = new DownWarnMsgExgInform();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        int index = dataIndex;
        obj.setWarnSrc(DecoderUtils.parseIntFromBytes(data, index, 1));
        index+=1;
        obj.setWarnType(DecoderUtils.parseIntFromBytes(data, index, 2));
        index+=2;
        obj.setWarnTime(GetDateUtc(data, index));
        index+=8;
        int len = DecoderUtils.parseIntFromBytes(data, index, 4);
        index+=4;
        obj.setWarnContent(DecoderUtils.parseStringFromBytes(data, index, len));
        index+=len;
        return obj;
    }

    //====================从链路车辆监管业务 ======================

    /**
     *  车辆单向监听请求消息
     * @param data
     */
    public DownCtrlMsgMonitorVehicleReq downCtrlMsgMonitorVehicleReq(byte[] data)
    {
        DownCtrlMsgMonitorVehicleReq obj = new DownCtrlMsgMonitorVehicleReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setMonitorTel(DecoderUtils.parseStringFromBytes(getDataBody(data)));
        return obj;
    }

    /**
     *  车辆拍照请求消息
     * @param data
     */
    public DownCtrlMsgTakePhotoReq downCtrlMsgTakePhotoReq(byte[] data)
    {
        DownCtrlMsgTakePhotoReq obj = new DownCtrlMsgTakePhotoReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setLensId(DecoderUtils.parseIntFromBytes(data, dataIndex, 1));
        obj.setSize(DecoderUtils.parseIntFromBytes(data, dataIndex+1, 1));
        return obj;
    }

    /**
     *  下发车辆报文请求消息
     * @param data
     */
    public DownCtrlMsgTextInfo downCtrlMsgTextInfo(byte[] data)
    {
        DownCtrlMsgTextInfo obj = new DownCtrlMsgTextInfo();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        int index = dataIndex;
        obj.setMsgSequence(DecoderUtils.parseIntFromBytes(data, index, 4));
        index+=4;
        obj.setMsgPriority(DecoderUtils.parseIntFromBytes(data, index, 1));
        index+=1;
        int len = DecoderUtils.parseIntFromBytes(data, index, 4);
        index+=4;
        obj.setMsgContent(DecoderUtils.parseStringFromBytes(data, index, len));
        index+=len;
        return obj;
    }

    /**
     *  上报车辆行驶记录请求消息
     * @param data
     */
    public DownCtrlMsgTakeTravelReq downCtrlMsgTakeTravelReq(byte[] data)
    {
        DownCtrlMsgTakeTravelReq obj = new DownCtrlMsgTakeTravelReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        obj.setCmdType(DecoderUtils.parseIntFromBytes(data, 28, 10));
//        obj.setStartTime(GetDateUtc(data, dataIndex));
//        obj.setEndTime(GetDateUtc(data, dataIndex+8));
        return obj;

    }
    /**
     *  车辆应急接入监管平台请求消息
     * @param data
     */
    public DownCtrlMsgEmergencyMonitoringReq downCtrlMsgEmergencyMonitoringReq(byte[] data)
    {
        DownCtrlMsgEmergencyMonitoringReq obj = new DownCtrlMsgEmergencyMonitoringReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        int index = dataIndex;
        obj.setAuthenticationCode(DecoderUtils.parseStringFromBytes(data, index, 10));
        index+=10;
        obj.setAccessPointName(DecoderUtils.parseStringFromBytes(data, index, 20));
        index+=20;
        obj.setUserName(DecoderUtils.parseStringFromBytes(data, index, 49));
        index+=49;
        obj.setPassWord(DecoderUtils.parseStringFromBytes(data, index, 22));
        index+=22;
        obj.setServerIp(DecoderUtils.parseStringFromBytes(data, index, 32));
        index+=32;
        obj.setTcpPort(DecoderUtils.parseIntFromBytes(data, index, 2));
        index+=2;
        obj.setUdpPort(DecoderUtils.parseIntFromBytes(data, index, 2));
        index+=2;
        obj.setEndTime(GetDateUtc(data, index));
        index+=8;
        return obj;
    }
    //=====================从链路车辆静态信息交换业务============================
    /**
     *  补报车辆静态信息请求消息
     * @param data
     */
    public DownBaseMsgVehicleAdded downBaseMsgVehicleAdded(byte[] data)
    {
        DownBaseMsgVehicleAdded obj = new DownBaseMsgVehicleAdded();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(data,0));
        return obj;
    }

    //=====================================1078视频=======================================

    /**
     * 远程录像回放控制消息
     * @param bodyBytes
     * @return
     */
    public DownPlayBackMsgControl downPlayBackMsgControl(byte[] bodyBytes) {
        DownPlayBackMsgControl obj = new DownPlayBackMsgControl();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(bodyBytes,0));
        int index = dataIndex;
        obj.setControlType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setFastType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setDateTime(GetDateUtc(bodyBytes, index));
        index+=8;
        return obj;
    }

    /**
     * 远程录像回放请求消息
     * @param bodyBytes
     * @return
     */
    public DownPlayBackMsgStartup downPlayBackMsgStartup(byte[] bodyBytes) {
        DownPlayBackMsgStartup obj = new DownPlayBackMsgStartup();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(bodyBytes,0));
        int index = dataIndex;
        obj.setChannelId(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setMediaType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setCodeType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setStorageType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setStartTime(GetDateUtc(bodyBytes, index));
        index+=8;
        obj.setEndTime(GetDateUtc(bodyBytes, index));
        index+=8;
        obj.setAuthorizeCode(DecoderUtils.parseStringFromBytes(bodyBytes, index,64));
        index+=64;
        //gpsdata
        index+=32;
        return obj;
    }

    /**
     * 主动请求停止实时音视频传输消息
     * @return
     */
    public DownRealVideoMsgEnd downRealVideoMsgEnd(byte[] bodyBytes) {
        DownRealVideoMsgEnd obj = new DownRealVideoMsgEnd();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(bodyBytes,0));
        int index = dataIndex;
        obj.setChannelId(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setMediaType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        return obj;
    }

    /**
     * 实时音视频请求消息
     * @param bodyBytes
     * @return
     */
    public DownRealVideoMsgStartup downRealVideoMsgStartup(byte[] bodyBytes) {
        DownRealVideoMsgStartup obj = new DownRealVideoMsgStartup();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(bodyBytes,0));
        int index = dataIndex;
        obj.setChannelId(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setMediaType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setAuthorizeCode(DecoderUtils.parseStringFromBytes(bodyBytes, index,64).trim());
        index+=64;
        //gpsdata
        index+=36;
        return obj;
    }

    /**
     * 主动上传音视频资源目录信息应答消息
     * @param bodyBytes
     * @return
     */
    public DownFileListMsgAck downFileListMsgAck(byte[] bodyBytes) {
        DownFileListMsgAck obj = new DownFileListMsgAck();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(bodyBytes,0));
        int index = dataIndex;
        obj.setResult(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setCount(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        return obj;
    }

    public DownRealVideoFileListReq downRealVideoFileListReq(byte[] bodyBytes) {
        DownRealVideoFileListReq obj = new DownRealVideoFileListReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(bodyBytes,0));
        int index = dataIndex;
        obj.setChannelId(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setStartTime(GetDateUtc(bodyBytes, index));
        index+=8;
        obj.setEndTime(GetDateUtc(bodyBytes, index));
        index+=8;
        String alarmHex = DecoderUtils.parseBcdStringFromBytes(bodyBytes, index, 8);
        obj.setAlarmType(alarmHex);
        obj.setMediaAlarmFlag(DecoderUtils.parseIntFromBytes(bodyBytes,index, 4));
        obj.setGpsAlarmFlag(DecoderUtils.parseIntFromBytes(bodyBytes,index+4, 4));
        index+=8;
        obj.setMediaType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setCodeType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setStorageType(DecoderUtils.parseIntFromBytes(bodyBytes, index, 1));
        index+=1;
        obj.setAuthorizeCode(DecoderUtils.parseStringFromBytes(bodyBytes, index, 64));
        index+=64;
        //gpsdata
        index+=36;
        return obj;
    }

    /**
     * 报警附件目录请求消息
     */
    public DownWarnMsgFileListReq downWarnMsgFileListReq(byte[] bodyBytes){
        DownWarnMsgFileListReq obj = new DownWarnMsgFileListReq();
        obj.setBasicVehicleInfo(GetBasicVehicleInfo(bodyBytes,0));
        int index = dataIndex;
        obj.setInfo_id(DecoderUtils.parseStringFromBytes(bodyBytes,index,32));
        index += 32;
        return obj;
    }

}
